import { _decorator, Component, Node, TextAsset, find, director } from 'cc';
import { CSVManager } from './csvManager';
import { storyView } from './storyView';
const { ccclass, property } = _decorator;

@ccclass('main')
export class main extends Component {
    private _csvManager: CSVManager = new CSVManager();
    /**csv文件 */
    @property({ displayName: "csv对话文本文件", tooltip: "对话内容", type: TextAsset })
    csv: TextAsset = null!

    /**选择哪个支线 */
    @property({ displayName: "支线id", tooltip: "支线id"})
    branchID: string = ''!

    start() {
        //加载CSV相关配置
        this._csvManager.addTable('example', this.csv.text,true);
        let currentJson = this._csvManager.queryAll('example','parent_id',this.branchID);
        console.log("currentJson",currentJson);
        let story = director.getScene().getChildByName("storyView").getComponent(storyView);
        story.init(currentJson);
    }

    // /**
    //  * 选择支线
    //  */
    //  selectBranch() {
    //     let list =this.csv.text.split('\n')
    //     let obj = {};
    //     list = list.filter((el) => { return el.parent_id == parent_id })

    //     list.map((e) => {
    //         obj[e.id] = e;
    //     })
    //     this.jsonData = obj

    // }

    update(deltaTime: number) {

    }
}


